#include <iostream>
#include <cstring>

class Student
{

public:
    //无参构造
    Student()
    {
        std::cout<<"无参构造"<<std::endl;
    };

    //带参构造

    Student(int age, const std::string & name)
    {
        m_age = age;
        m_name = name;
        std::cout<<"带2参构造"<<std::endl;
    }

    Student(const std::string & name)
    {
        m_age = 0;
        m_name = name;
        std::cout<<"带1参构造"<<std::endl;
    }
    //拷贝构造函数
    Student (const Student & s)
    {
        std::cout<<"拷贝构造函数"<<std::endl;
        m_age = s.m_age;
        m_name = s.m_name;
    }

    void setAge(int age);
    int getAge();
    void setName(const std::string& name);//常引用解决无法引用右值的问题
    //类内声明
    std::string getName();
    void operator = (const Student &s);
    ~Student()
    {
        std::cout<<"析构函数"<<std::endl;
    }
private:
    int m_age;
    std::string m_name;

};

//类外定义
std::string Student::getName()
{
    return m_name;
}

void Student::setAge(int age)
{
    m_age = age;
}

int Student::getAge()
{
    return m_age;
}

void Student::setName(const std::string &name)
{
    m_name = name;
}

void Student::operator=(const Student &s)
{
    std::cout<<"赋值运算符的重载"<<std::endl;
    m_age = s.m_age;
    m_name = s.m_name;
}



void func(Student & s)
{

}

int main()
{
    Student s(1, "zhangsan");
    // s.setAge(10);
    // s.setName("zhangsan");
    //std::cout<<s.getAge()<<std::endl;
    // std::cout<<s.getName()<<std::endl;
    std::cout<<s.getAge()<<" "<<s.getName()<<std::endl;

    
    Student s1 = s;
    std::cout<<s.getAge()<<" "<<s.getName()<<std::endl;

    Student s2;
    s2 = s;
    std::cout<<s.getAge()<<" "<<s.getName()<<std::endl;

    return 0;
}
